package util;

/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2000
 * Company:
 * @author
 * @version 1.0
 */
import java.io.*;
import java.util.*;

public class PersistenceMgr
{
   public PersistenceMgr()
   {
   }
   public static void save(Hashtable ht, String fileName) {
      try {
         ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream
            (fileName));
         oos.writeObject(ht);
         oos.flush();
         oos.close();
      } catch (IOException e) { e.printStackTrace(); }
   }
   public static void save(String[] strArray, String fileName) {
      try {
         PrintWriter pw=new PrintWriter(new FileWriter(fileName));
         for(int i=0; i<strArray.length; i++)
            pw.println(strArray[i]);
         pw.flush();
         pw.close();
      } catch (IOException e) { e.printStackTrace(); }
   }
   public static String[] load(String[] strArray, String fileName) {
      try {
         BufferedReader br=new BufferedReader(new FileReader(fileName));
         String line="";
         ArrayList al=new ArrayList();
         while ((line=br.readLine())!=null) al.add(line);
         strArray=new String[al.size()];
         al.toArray(strArray);
         br.close();
      } catch (IOException e) { e.printStackTrace(); return null; }
      return strArray;
   }
   public static Object load(ArrayList ht, String fileName) {
      try {
         ObjectInputStream ois=new ObjectInputStream(new
            FileInputStream(fileName));
         ht=(ArrayList)ois.readObject();
         ois.close();
      } catch (ClassNotFoundException e) { e.printStackTrace(); }
      catch (IOException e2) {
         ht=new ArrayList();
      }
      return ht;
   }
   public static void save(ArrayList ht, String fileName) {
      try {
         ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream
            (fileName));
         oos.writeObject(ht);
         oos.flush();
         oos.close();
      } catch (IOException e) { e.printStackTrace(); }
   }
   public static Object load(Hashtable ht, String fileName) {
      try {
         ObjectInputStream ois=new ObjectInputStream(new
            FileInputStream(fileName));
         ht=(Hashtable)ois.readObject();
         ois.close();
      } catch (ClassNotFoundException e) { e.printStackTrace(); }
      catch (IOException e2) {
         ht=new Hashtable();
      }
      catch (ClassCastException e3) {
         System.out.println("ClassCastException "+fileName);
      }
      return ht;
   }
   public static Object load(Vector ht, String fileName) {
      try {
         ObjectInputStream ois=new ObjectInputStream(new
            FileInputStream(fileName));
         ht=(Vector)ois.readObject();
         ois.close();
      } catch (ClassNotFoundException e) { e.printStackTrace(); }
      catch (IOException e2) {
         ht=new Vector();
      }
      return ht;
   }
   public static void save(Vector ht, String fileName) {
      try {
         ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream
            (fileName));
         oos.writeObject(ht);
         oos.flush();
         oos.close();
      } catch (IOException e) { e.printStackTrace(); }
   }
}
